home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / libs / winlib-0.0 / winlib-0 / win / demo / demo.c next >
Encoding:
C/C++ Source or Header  |  1996-01-02  |  4.4 KB  |  153 lines

  1. /*
  2.  * WinLIB Demonstration program
  3.  * by Ken Hollis
  4.  */
  5.  
  6. #include <winlib.h>
  7.  
  8. int file_index, options_index, settings_index, c1, c2, shown;
  9. WINDOW *t1_win, *t2_win;
  10.  
  11. void test_stop(void)
  12. {
  13.     Win_Deinitialize();
  14.     exit(0);
  15. }
  16.  
  17. void test_win_callback(WINDOW *win, int msg)
  18. {
  19.     switch(msg) {
  20.     case WM_CREATED:    wprintw(win, "Created\n");    break;
  21.     case WM_MINIMIZED:    wprintw(win, "Minimized\n");    break;
  22.     case WM_MAXIMIZED:    wprintw(win, "Maximized\n");    break;
  23.     }
  24. }
  25.  
  26. void test_window(void)
  27. {
  28.     Win_CreateWindow(0, 1, 40, 9, "Ook-Bleah!",
  29.     (CLOSER | MOVER | MAXIMIZER | MINIMIZER | SIZER), test_win_callback);
  30. }
  31.  
  32. void test2_win(void)
  33. {
  34.     (void) Win_CreateWindow(15, 15, 40, 9, "Ook-Bleah AGAIN",
  35.     (CLOSER | MOVER | MAXIMIZER | MINIMIZER | SIZER), test_win_callback);
  36. }
  37.  
  38. void c1_opt(void)
  39. {
  40.     c1 = (c1 == TRUE) ? FALSE : TRUE;
  41.     Menu_AddCheck(settings_index, "Opaquely", c1);
  42. }
  43.  
  44. void c2_opt(void)
  45. {
  46.     c2 = (c2 == TRUE) ? FALSE : TRUE;
  47.     Menu_AddCheck(settings_index, "Color", c2);
  48. }
  49.  
  50. void test_getlib(void)
  51. {
  52.     int x = Win_GetOptions();
  53.  
  54.     if (!shown)
  55.     shown++;
  56.     else
  57.     wprintw(_main_win, "What, once isn't enough?!\n");
  58.  
  59.     wprintw(_main_win, "Current library version: %s\n", Win_GetLibraryVersion());
  60.     wprintw(_main_win, "Current library options are:\n");
  61.     if (x & OPT_DEBUG)
  62.     wprintw(_main_win, "\tDebugging enabled\n");
  63.     if (x & OPT_MOUSECOORD)
  64.     wprintw(_main_win, "\tMouse coordinates enabled\n");
  65.     if (x & OPT_COLOR)
  66.     wprintw(_main_win, "\tColor support enabled\n");
  67.     if (x & OPT_SOUND)
  68.     wprintw(_main_win, "\tSound support enabled\n");
  69.     if (x & OPT_WAVFILE)
  70.     wprintw(_main_win, "\tMicrosoft WAV file support enabled\n");
  71.     if (x & OPT_USEDEVAUDIO)
  72.     wprintw(_main_win, "\tUsing /dev/audio to play Sun Audio sounds\n");
  73.     if (x & OPT_SOUNDINIT)
  74.     wprintw(_main_win, "\tConnection to sound server is established\n");
  75. }
  76.  
  77. void do_demo(void)
  78. {
  79.     c1 = FALSE;
  80.     c2 = FALSE;
  81.     t1_win = NULL;
  82.     t2_win = NULL;
  83.     shown = 0;
  84.  
  85.     file_index = Menu_AddTitle(" File ");
  86.     options_index = Menu_AddTitle(" Options ");
  87.     settings_index = Menu_AddTitle(" Settings ");
  88.  
  89.     if (file_index) {
  90.     Menu_AddItem(file_index, " Open a file  [ALT-O] ", MENU_SELECTABLE, NULL);
  91.     Menu_AddItem(file_index, " Close a file [ALT-C] ", MENU_SELECTABLE, NULL);
  92.     Menu_AddItem(file_index, " Save a file  [ALT-S] ", MENU_SELECTABLE, NULL);
  93.     Menu_AddItem(file_index, " -------------------- ", MENU_DISABLED, NULL);
  94.     Menu_AddItem(file_index, " Quit         [CTL-C] ", MENU_SELECTABLE, test_stop);
  95.     } else {
  96.     printf("Could not add menu items to the file (%d) index!\r\n", file_index);
  97.     printf("Program exits.\r\n");
  98.     exit(-1);
  99.     }
  100.  
  101.     if (options_index) {
  102.     Menu_AddItem(options_index, " Display a color dialog ", MENU_SELECTABLE, NULL);
  103.     Menu_AddItem(options_index, " Display a window       ", MENU_SELECTABLE, test_window);
  104.     Menu_AddItem(options_index, " Sample options dialog  ", MENU_SELECTABLE, test2_win);
  105.     Menu_AddItem(options_index, " ---------------------- ", MENU_DISABLED, NULL);
  106.     Menu_AddItem(options_index, " Save options           ", MENU_SELECTABLE, NULL);
  107.     Menu_AddItem(options_index, " ---------------------- ", MENU_DISABLED, NULL);
  108.     Menu_AddItem(options_index, " Get library version    ", MENU_SELECTABLE, test_getlib);
  109.     } else {
  110.     printf("Could not add menu items to the options (%d) index!\r\n", options_index);
  111.     printf("Program exits.\r\n");
  112.     exit(-1);
  113.     }
  114.  
  115.     if (settings_index) {
  116.     Menu_AddItem(settings_index, "  Dialogs move Opaquely ", MENU_SELECTABLE, c1_opt);
  117.     Menu_AddItem(settings_index, "  Color Display         ", MENU_SELECTABLE, c2_opt);
  118.     } else {
  119.     printf("Could not add menu items to the settings (%d) index!\r\n", settings_index);
  120.     printf("Program exits.\r\n");
  121.     exit(-1);
  122.     }
  123.  
  124.     Win_Loop();
  125.     Win_Deinitialize();
  126. }
  127.  
  128. void demo_keyboard(int c)
  129. {
  130.     wprintw(_main_win, "Keyboard: %d\n", c);
  131. }
  132.  
  133. void main(void)
  134. {
  135.     if (Win_Initialize()) {
  136.     if (Win_InitializeSound()) {
  137.         Win_SetSound(SOUND_OPEN, "/home/khollis/dev/win/demo/Tenchi-opening.au");
  138.     } else {
  139.         wprintw(_main_win, "Uh oh, the sound server isn't running.\n");
  140.         wprintw(_main_win, "Better type \"sound_server &\" before running this\n");
  141.         wprintw(_main_win, "program again.  Sound support will be disabled for\n");
  142.         wprintw(_main_win, "this program session.\n");
  143.     }
  144.     Win_SetCallbackKEYBOARD(demo_keyboard);
  145.     Win_PlaySound(SOUND_START);
  146.     do_demo();
  147.     Win_Deinitialize();
  148.     } else {
  149.     printf("Cannot initialize.\n");
  150.     exit(0);
  151.     }
  152. }
  153.